﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SubSonic;
using LinFen;

public partial class webUserControl_CustomerList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Cookies aCookies = new Cookies();
            if (aCookies.getCookies("cFlag") == "0")
            {
                GridView1.DataSourceID = "sqldatasource3";
                GridView1.DataBind();
            }
            else
            {
                GridView1.DataSourceID = "sqldatasource4";
                GridView1.DataBind();
            }
            if (aCookies.getCookies("cistype") == "1")
            {
                Panel1.Visible = false;
            }
        }
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/CustomerAdd.aspx");
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "ShanChu")
        {
            int cID = int.Parse(e.CommandArgument.ToString());
            StoredProcedure sp = new StoredProcedure("sp_CustomerTimeOut");
            sp.Command.AddParameter("@cID", cID);
            sp.Execute();
            Query q = new Query("CustomerInfo");
            q.AddWhere("ID", cID);
            IDataReader dr = q.ExecuteReader();
            if(dr.Read())
            {
                string cName = dr["customerName"].ToString();
                AdminInfo.Delete("AdminName", cName);

                CustomerInfo.Delete("ID", cID);
            }
        }
       GridView1.DataBind();
    } 
}
